// pages/login/index.js
Page({
data:{
    top:'请登录:'
},
onLoad:function(){
    wx.hideHomeButton({
      success: (res) => {},
    })
},
onShow:function() {
    if(wx.getStorageSync('un')!=''&&wx.getStorageSync('pwd')!=''){
        _login(this);
    }
},
login:function(data){
    let un=data.detail.value.un
    let pwd=data.detail.value.pwd
    if(un!=''&&pwd!=''){
        wx.setStorageSync('un',un);
        wx.setStorageSync('pwd',pwd);
        _login(this);
    }else{
        this.setData({
            top:'请输入账号密码'
        })
    }
},
visiter:function() {
    wx.setStorageSync('un','visiter');
    wx.setStorageSync('pwd','8888');
    _login(this);
}
})
function _login(that){
    that.setData({
        top:'登录中'
    })
    wx.request({
        url: 'https://service-czcepxfq-1300390346.gz.apigw.tencentcs.com/release/table?username='+wx.getStorageSync('un')+'&password='+wx.getStorageSync('pwd'),
        method:'GET',
        success:function(res) {
            let data={}
            data.data=res.data
            if (res.statusCode==200){
                wx.request({
                    url: 'https://service-czcepxfq-1300390346.gz.apigw.tencentcs.com/release/table',
                    method:'GET',
                    success:function(res) {
                        data.week=res.data
            
                        let date=new Date()
                        let day=date.getDay()
                        if(day==0){day=7}
                        data.time=date.getTime()-(day-1)*(1000*60*60*24)
                        wx.redirectTo({
                        url: '/pages/index/index',
                        success: function() {
                            wx.setStorageSync('data',data);
                        }
                    });
                    }
                  })
        }else{
            that.setData({
                top:data
            })
        }
        }
    })
}